package com.onedec.designer.service.impl;

import com.onedec.designer.entity.OnedecFloorPlan;
import com.onedec.designer.entity.OnedecFloorPlanExample;
import com.onedec.designer.mapper.OnedecFloorPlanMapper;
import com.onedec.designer.service.OnedecFloorPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OnedecFloorPlanServiceImpl implements OnedecFloorPlanService {
    @Autowired
    private OnedecFloorPlanMapper onedecFloorPlanMapper;

    @Override
    public List<OnedecFloorPlan> findAll() {
        return onedecFloorPlanMapper.selectByExample(null);
    }

    @Override
    public List<Map<String, Object>> selectByMap(Map<String, Object> map) {
        return onedecFloorPlanMapper.selectByMap(map);
    }

    @Override
    public long accountnum() {
        return onedecFloorPlanMapper.countByExample(null);
    }

    @Override
    public void deleteById(int id) {
        onedecFloorPlanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertOne(OnedecFloorPlan onedecFloorPlan) {
        onedecFloorPlanMapper.insertSelective(onedecFloorPlan);
    }

    @Override
    public List<OnedecFloorPlan> selectByProjectId(int id) {
        OnedecFloorPlanExample onedecFloorPlanExample = new OnedecFloorPlanExample();
        OnedecFloorPlanExample.Criteria or = onedecFloorPlanExample.or();
        or.andFloorProjectIdEqualTo(id);

        return onedecFloorPlanMapper.selectByExample(onedecFloorPlanExample);
    }

    @Override
    public OnedecFloorPlan selectById(int id) {
        return onedecFloorPlanMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(OnedecFloorPlan onedecFloorPlan) {
        onedecFloorPlanMapper.updateByPrimaryKeySelective(onedecFloorPlan);
    }

    @Override
    public void updateById(int id) {
        OnedecFloorPlan onedecFloorPlan = onedecFloorPlanMapper.selectByPrimaryKey(id);
        onedecFloorPlan.setFloorStatus("1");
        onedecFloorPlanMapper.updateByPrimaryKeySelective(onedecFloorPlan);
    }

    @Override
    public void rejectById(int id) {
        OnedecFloorPlan onedecFloorPlan = onedecFloorPlanMapper.selectByPrimaryKey(id);
        onedecFloorPlan.setFloorStatus("3");
        onedecFloorPlanMapper.updateByPrimaryKeySelective(onedecFloorPlan);
    }
}
